import { sendAddCommentRequest, getCommentList, delCommentList } from '@/http/requestFunction'

export default {
    namespaced: true,
    actions: {
        // 发送添加请求
        async sendAddCommentRequest(content, val) {
            try {
                if(val.comment === ''){
                    return
                }else{
                    const res = await sendAddCommentRequest(val.comment, val.username, val._id)
                    console.log(res)
                }
                
            } catch (e) {
                console.log(e)
            }
        },

        // 获取评论数据
        async getCommentList(content, _id) {
            try {
                const res = await getCommentList(_id)
                // console.log(res.data.comment)
                content.commit('GETCOMMENTLIST', res.data.comment)

            } catch (e) {
                console.log(e)
            }
        },

        // 提交删除评论请求
        async delCommentList(content, info) {
            try{
                const res = await delCommentList(info._id,info.comment_id)
                console.log(res)

            }catch(e){
                console.log(e)
            }
        }

    },
    mutations: {
        GETCOMMENTLIST(state, list) {
            state.commentList = list
        }
    },
    state: {
        commentList: []
    }

}